<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Title</title>
</head>
<link href="../css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="../css/bootstrap-table.min.css">

<script src="../js/jquery-3.3.1.js"></script>
<script src="../js/bootstrap.bundle.min.js"></script>
<script src="../js/bootstrap-table.min.js"></script>
<script src="../js/bootstrap-table-zh-CN.min.js"></script>

<style>
    body
    {
        background-color: #f5f3e9;
    }

    #back
    {
        background-color: white;
        width: 800px;
        height: 500px;
        border: solid 1px black;
        box-shadow: 8px 8px 5px -4px rgb(0,0,0);
    }

    .input
    {
        border-bottom: 1px solid black;
        border-top:0px;
        border-left:0px;
        border-right:0px;
        outline: none;
    }

    .a
    {
        border-bottom:0px;
        border-top:0px;
        border-left:0px;
        border-right:0px;
        outline: none;
    }
</style>
<style>
    body {
        background-color: #d1ecf1;
    }
</style>
<body>
<DIV class="row" style="margin-top: 10px;margin-left: 20px;">
    <DIV class="col text-left">
        <span style="color: #0c84ff;">安全库存配置单-制定安全库存配置单</span>
    </DIV>
</DIV>
<hr>
    <div>
        <div class="row">
            <div class="col">
                <caption>
                    <div style="margin-left: 1000px">
                        <input type="button" class="btn btn-outline-primary" onclick="tijiao()" value="提交">
                        <input type="button" class="btn btn-outline-dark" onclick="fhaq()" VALUE="返回">
                    </div>
                </caption>
                <input type="hidden" id="id" value="${dfile.id}">
                <input type="hidden" id="type" value="${dfile.type}">
                <input type="hidden" id="realcostprice" value="${dfile.costprice}">
                <input type="hidden" id="productdescribe" value="${dfile.productdescribe}">
                <div   id="back"  class="container">
                    <div class="text-center">
                        <h4 style="margin-top: 20px">安全库存配置单</h4>
                    </div>

                    <div class="form-group">
                        <div class="row">
                            <div style="margin-top: 20px" class="col">
                                <span style="margin-left: 50px">产 品 名 称:&nbsp&nbsp</span><input class="input"  type="text" id="prouctname" value="${dfile.productname}"/>
                                <span style="margin-left: 100px">产 品 编 号:&nbsp&nbsp</span><input class="input"  type="text" id="prouctid" value="${dfile.productid}"/>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="row">
                            <div class="col">
                                <span style="margin-left: 50px">库存报警下限数:&nbsp&nbsp</span><input class="input" id="minamount"  type="text"/>
                                <span style="margin-left: 65px">库存报警上限数:&nbsp&nbsp</span><input class="input" id="maxamount"  type="text"/>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="row">
                            <div class="col">
                                <table  style="margin-top: 30px;text-align: center" class="container" border="1" width="750px">
                                    <tr style="background-color: #b3d2f2">
                                        <td>序号</td>
                                        <td>库房名称</td>
                                        <td>存储地址编号</td>
                                        <td>存储地址名称</td>
                                        <td>最大存储量</td>
                                        <td>单位</td>
                                    </tr>

                                    <tr>
                                        <td>1</td>
                                        <td>1</td>
                                        <td>1</td>
                                        <td>1</td>
                                        <td style="background-color: #faf1b0"><input style="background-color: #faf1b0" type="text" class="a" size="5" id="maxcapacityamount" ></td>
                                        <td style="background-color: #faf1b0"><input style="background-color: #faf1b0" type="text" class="a" size="5" id="amountunit" ></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div style="margin-top: 20px" class="col">
                            <span style="margin-left: 100px">登 记 人:&nbsp&nbsp</span><input class="input" type="text" id="register" value="${name}"/>
                            <span style="margin-left: 80px">登 记 时 间:&nbsp&nbsp</span><span id="date" ></span>
                        </div>
                    </div>

                    <div class="row">
                        <div style="margin-top: 70px" class="col">
                            <span style="margin-left: 75px;vertical-align: middle;margin-top: 40px">配 置 要 求:</span>
                        </div>
                    </div>

                    <div class="row">
                        <div style="margin-bottom: 50px;margin-left: 180px;transform:translateY(-60%)" class="col">
                            <textarea style="width: 550px;height: 100px" id="config" ></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script>
    function tijiao() {
        let maxcapacityamount=$("#maxcapacityamount").val();//最大存储量
        let minamount=$("#minamount").val();//库存报警下限数
        let maxamount=$("#maxamount").val();//库存报警上限数
        let id = $("#id").val();
        let realcostprice = $("#realcostprice").val();
        let productdescribe = $("#productdescribe").val();
        let prouctname=$("#prouctname").val();//产 品 名 称
        let prouctid=$("#prouctid").val();//产 品 编 号
        let register=$("#register").val()//登记人
        let config=$("#config").val();//配置要求
        let amountunit=$("#amountunit").val()//单位
        let type=$("#type").val()//用途类型
        let min =  Math.trunc(minamount);
        let max = Math.trunc(maxamount);
        let num = Math.trunc(maxcapacityamount);
    if (min>max)
        {
            alert("库存报警下限数必须小于库存报警上限数")
            return;
        }
    if (max>num)
        {
            alert("上限不能大于总储存量");
            return;
        }
        let scell = {prouctname:prouctname,prouctid:prouctid,maxcapacityamount:maxcapacityamount,
                minamount:minamount,maxamount:maxamount,realcostprice:realcostprice,productdescribe:productdescribe,
                id:id,register:register,config:config,amountunit:amountunit,type:type}
        if (isNaN(min) || min=="" || min==0)
        {
            alert("库存报警下限数必须是数字且不能为空")
            return;
        }else if (isNaN(max) || max=="" || max==0)
        {
            alert("库存报警上限数必须是数字且不能为空")
            return;
        }else
        if (isNaN(num) || num=="" || num==0)
        {
            alert("存储量必须是数字且不能为空");
            return;
        }
        $.ajax({
            url: "/insert",
            type: "POST",
            data: JSON.stringify(scell),
            datatype:"json",
            contentType:"application/json",
            success:function(data){
                if (data==1){
                    location.href="xiao_wen_bo/aqkucun.jsp";
                }
            }
        });

    }


    function fhaq() {
        location.href="xiao_wen_bo/aqkucun.jsp";
    }

    function showTime() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;  //因为month属性从0开始所以加1
        var day = date.getDate();   // 日


        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        second = second < 10 ? "0" + second : second;
        var current = year + "-" + month + "-" + day + " "+ " " + hour + ":" + minute + ":" + second;
        document.getElementById("date").innerHTML = current;
    }

    setInterval("showTime()", 1000);//每隔1000毫秒（即1秒）显示一次当前时间
</script>
